package cn.ekuma.epos.module;

import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.util.Collection;
import java.util.List;

import javax.swing.JComponent;
import javax.swing.JToolBar;
import javax.swing.JScrollPane;
import javax.swing.JList;
import javax.swing.BoxLayout;

import net.xeoh.plugins.base.PluginManager;
import net.xeoh.plugins.base.util.PluginManagerUtil;

import cn.ekuma.epos.datalogic.I_DataLogicERP;
import cn.ekuma.epos.datalogic.I_DataLogicSystem;

import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.I_Session;

import com.openbravo.pos.base.AppView;
import com.openbravo.pos.base.BeanFactoryApp;
import com.openbravo.pos.base.BeanFactoryException;
import com.openbravo.pos.base.I_AppView;
import com.openbravo.pos.forms.JPanelView;

import java.awt.Dimension;

public class JModuleManagerPanel extends JPanel implements JPanelView, BeanFactoryApp{

	
	List<Module> insertModules;
	private PluginManager pmf;
	private JPanel panel;
	private I_DataLogicSystem dlSystem;
	private I_Session s;
	private I_DataLogicERP dlSales;
	
	/**
	 * Create the panel.
	 */
	public JModuleManagerPanel() {

		initComponents();
	}
	private void initComponents() {
		setLayout(new BorderLayout(0, 0));
		
		JToolBar toolBar = new JToolBar();
		add(toolBar, BorderLayout.NORTH);
		
		JList list = new JList();
		list.setPreferredSize(new Dimension(180, 0));
		add(list, BorderLayout.WEST);
		
		JScrollPane scrollPane = new JScrollPane();
		add(scrollPane, BorderLayout.CENTER);
		
		panel = new JPanel();
		scrollPane.setViewportView(panel);
		panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
	}
	@Override
	public String getTitle() {
		return null;
	}
	@Override
	public void activate() throws BasicException {
		PluginManagerUtil pmu = new PluginManagerUtil(pmf);
		panel.removeAll();
		/**Collection<I_AppModule>  appModules=pmu.getPlugins(I_AppModule.class);
		for(I_AppModule appModule:appModules){
			appModule.init(dlSales);
			appModule.init(s);
			appModule.setInsertedModule(dlSystem.findModuleById(appModule.getModuleName()));
			ModuleEntryPanel modulePanel=new ModuleEntryPanel();
			modulePanel.init(appModule);
			panel.add(modulePanel);
		}*/
	}
	@Override
	public boolean deactivate() {
		return true;
	}
	@Override
	public JComponent getComponent() {
		return this;
	}
	@Override
	public Object getBean() {
		return this;
	}
	@Override
	public void init(I_AppView app) throws BeanFactoryException {
		//pmf=app.getPluginManager();
		//s=app.getSession();
		//dlSystem = (I_DataLogicSystem) app.getBean("com.openbravo.pos.forms.I_DataLogicSystem");
	    //dlSales = (I_DataLogicERP) app.getBean("com.openbravo.pos.forms.I_DataLogicSales");
	}

}
